<?php
if ( phpversion() >= "4.2.0")
{  
    extract($_POST);  
    extract($_GET);  
    extract($_SERVER);  
} 

require_once "include/config.php";
require_once "include/functions.php";

include_only();

$srt = export_subtitle($subtitle_id);
//echo $srt;

$temp_file_name = "tmp/" . getmicrotime(). generate_random_number("11111111111111", "9999999999999");
//echo $temp_file_name;

//writing .srt file to server
$myFile = $temp_file_name;
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $srt;
fwrite($fh, $stringData);
fclose($fh);
//

$subtitle_info = get_subtitle_info($subtitle_id);
//print_r($subtitle_info);
$video_id = $subtitle_info['video_id'];
$user_id = $subtitle_info['user_id'];
$language = $subtitle_info['language'];
 
$video_info = get_video_information($video_id);
$video_name = $video_info['name']; 
//print_r($video_info);

$user_info = get_user_info($user_id);
$user_name = $user_info['username'];
//print_r($user_info);

$language_info = get_language_by_id($language);
$language_name = $language_info['name'];
//print_r($language_info);

$file_download_name = $video_name . " " . $language_name . " by " . $user_name . ".srt";
$file_download_name = str_replace(" ","_",$file_download_name);
$file_download_name = str_replace("("," ",$file_download_name);
$file_download_name = str_replace(")"," ",$file_download_name);
//echo $file_download_name;

header ("Content-Type: plain/text");
header ("Content-Disposition: attachment; filename=$file_download_name");
header("Content-Length: " . filesize("$temp_file_name"));
$fp = fopen("$temp_file_name", "r");
fpassthru($fp);
?>

